home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / insttest / lea_adda.s < prev    next >
Text File  |  1985-11-19  |  8KB  |  187 lines

  1.  ; Program Name: LEA_ADDA.S
  2.  ; Version 1.004
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;    Assemble in PC-relative mode and save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Execute from the desktop; or execute SPAWN.TTP, type LEA_ADDA.TOS on
  11.  ; its command line and view this program's output in LEA_ADDA.DAT.
  12.  
  13.  ; Program Function:
  14.  
  15.  ;    Confirms (or refutes) the contention that lea $C(An), An is faster
  16.  ; than adda.l #$C(An), where n = 1 - 7.  Reference: "68000 Tricks and Traps",
  17.  ; by Mike Morton, p.166, Byte, September, 1986.  See the paragraph which
  18.  ; begins "Small adjustments to the stack pointer...".
  19.  
  20. calculate_program_size:
  21.  lea        -$102(pc), a1       ; Fetch basepage start address.
  22.  lea        program_end, a0     ; Fetch program end address.
  23.  trap       #6                  ; Return unused memory to op system.
  24.  lea        stack, a7           ; Point A7 to this program's stack.
  25.  
  26. print_heading:
  27.  lea        heading, a0
  28.  bsr        print_string
  29.  
  30. lea_method:
  31.  lea        lea_time_msg, a0    ; Print label for lea execution results.
  32.  bsr        print_string
  33.  move.l     #49999, d7          ; D7 is counter for the loop.
  34.  trap       #3                  ; Value of system clock returned in D0.
  35.  move.l     d0, d1              ; Save time in scratch register.
  36.  
  37. lea_loop:                       ; Marks start of instruction in the loop.
  38.  lea        $C(a2), a2          ; Instruction in the loop.
  39. memory_1:                       ; Marks end of instruction in the loop.
  40.  dbra       d7, lea_loop        ; Loop 50000 times.
  41.  trap       #3                  ; Get current value of system clock.
  42.  sub.l      d1, d0              ; Subtract beginning value from ending value.
  43.  mulu       #5, d0              ; Convert to milliseconds.
  44.  sub.l      #80, d0             ; Subtract dbra time and "error".
  45.                                 ; See Timing Note below.
  46.  move.l     d0, d1              ; Transfer time for trap #4 call.
  47. convert_lea_time_to_ASCII_decimal:
  48.  trap       #4                  ; Address of decimal string returned in A0.
  49. print_lea_time:
  50.  bsr.s      print_string        ; Print the decimal string.
  51.  lea        time_msg, a0        ; Print units label.
  52.  bsr.s      print_string
  53.  
  54.  ; Timing Note:
  55.  
  56.  ;   Until the count has expired, each dbra instruction requires 10 clock
  57.  ; periods to execute.  49,999 dbra instructions require that amount of
  58.  ; time.  When the last dbra instruction is executed, the count has expired
  59.  ; and that instruction requires 14 clock periods.
  60.  
  61.  ;   Total clock periods consumed by the dbra instruction is 
  62.  
  63.  ;                  49,999 X 10 + 14 = 500,004.
  64.  
  65.  ;   Each clock period is .000000125 second.  Total time consumed by the
  66.  ; dbra instructions is
  67.  
  68.  ;        500,004 X .000000125 = .0625 second = 62.5 milliseconds.
  69.  
  70.  ;   If we assume that the 8 clock period execution time given in the
  71.  ; Motorola reference manual for the lea d(An) instruction is correct,
  72.  ; then 50,000 executions of lea $C(a2), a2 require 
  73.  
  74.  ;            50,000 X 8 X .000000125 = 50 milliseconds
  75.  
  76.  ;   Total time for the lea loop is 62.5 + 50 = 112.5 milliseconds.
  77.  
  78.  ;   When no adjustment is made for "overhead" time, such as attendant
  79.  ;   instructions, which includes the dbra instruction, trap invocations and
  80.  ;   a few others, this program reports a lea loop execution time of 130
  81.  ;   milliseconds.  We can assume that the excess 17.5 milliseconds (130-112.5)
  82.  ;   is partially due to the "overhead" time and partially due to a system
  83.  ;   clock frequency different from 8 mhz.  We can simply combine both
  84.  ;   components into "overhead" time.
  85.  
  86.  ;   With no adjustment for "overhead" time this program reports a loop
  87.  ;   execution time of 180 milliseconds for the adda.l #$C, a2 loop.  We
  88.  ;   subtract the 17.5 milliseconds "overhead" from this to obtain the true
  89.  ;   loop time of 162.5 milliseconds.
  90.  
  91.  ;   From this we subtract the dbra execution time of 62.5 milliseconds to
  92.  ;   get 100 milliseconds for 50,000 adda.l instruction..
  93.  
  94.  ;       62.5 milliseconds / 50,000 = .000002 second per instruction.
  95.  
  96.  ;         .000002 / .000000125 = 16 clock periods per instruction 
  97.  
  98.  ;   The execution time given in the Motorola manual for the adda.l #d, An 
  99.  ;   instruction is 16 clock periods.
  100.  
  101.  ;   These calculations validate the method and justify subtracting the
  102.  ;   "overhead" time from the total loop execution times before printing the
  103.  ;   execution time for 50,000 executions of each of the two instructions of
  104.  ;   interest.  Finally, we can combine dbra time and "overhead" time into
  105.  ;   a "new" overhead time that is 17.5 + 62.5 = 80 milliseconds.
  106.  
  107.  ;   When the adjustments are made to the recorded loop times, the program
  108.  ;   prints out the correct time for 50,000 executions of each instruction,
  109.  ;   and the output correctly indicates that the lea instruction used in
  110.  ;   the program is twice as fast as the adda.l instruction used.  The 
  111.  ;   execution results of the program agree with the timing data given in
  112.  ;   the Motorola reference guide.
  113.  
  114. adda_method:
  115.  lea        adda_time_msg, a0   ; Print label for adda execution results.
  116.  bsr.s      print_string
  117.  move.l     #49999, d7          ; D7 is counter for the loop.
  118.  trap       #3                  ; Value of system clock returned in D0.
  119.  move.l     d0, d1              ; Save time in scratch register.
  120.  
  121. adda_loop:                      ; Marks start of instruction in the loop.   
  122.  adda.l     #$C, a2             ; Instruction in the loop.
  123. memory_2:                       ; Marks end of instruction in the loop.
  124.  dbra       d7, adda_loop       ; Loop 50000 times.
  125.  trap       #3                  ; Get current value of system clock.
  126.  sub.l      d1, d0              ; Subtract beginning value from ending value.
  127.  mulu       #5, d0              ; Convert to milliseconds.
  128.  sub.l      #80, d0             ; Subtract dbra time and "error".
  129.  move.l     d0, d1              ; Transfer time for trap #4 call.
  130. convert_adda_time_to_ASCII_decimal:
  131.  trap       #4                  ; Address of decimal string returned in A0.
  132. print_adda_time:
  133.  bsr.s      print_string        ; Print the decimal string.
  134.  lea        time_msg, a0        ; Print units label.
  135.  bsr.s      print_string
  136.  
  137. print_lea_requisite_memory:
  138.  lea        lea_memory_msg, a0
  139.  bsr.s      print_string
  140.  lea        memory_1, a0        ; Calculate number of bytes occupied by the
  141.  lea        lea_loop, a1        ; instruction in the loop.
  142.  bsr.s      print_requisite_memory
  143.  
  144. print_adda_requisite_memory:
  145.  lea        adda_memory_msg, a0
  146.  bsr.s      print_string
  147.  lea        memory_2, a0        ; Calculate number of bytes occupied by the
  148.  lea        adda_loop, a1       ; instruction in the loop.
  149.  bsr.s      print_requisite_memory
  150.  
  151. terminate:
  152.  trap       #8
  153.  
  154.  ; SUBROUTINES
  155.  
  156. print_requisite_memory:
  157.  suba.l     a1, a0
  158.  move.l     a0, d1
  159.  trap       #4                  ; Returns address of decimal string in A0.
  160.  bsr.s      print_string
  161.  lea        memory_msg, a0
  162.  bsr.s      print_string
  163.  rts
  164.  
  165. print_string:                   ; Expects address of string to be in A0.
  166.  pea        (a0)                ; Push address of string onto stack.
  167.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  168.  trap       #1                  ; GEMDOS call
  169.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  170.  rts
  171.  
  172.  data
  173. heading:         dc.b $D,$A,'LEA_ADDA Execution Results',$D,$A,$D,$A,0
  174. lea_time_msg:    dc.b '   Time for 50,000 lea instructions:     ',0
  175. adda_time_msg:   dc.b '   Time for 50,000 adda.l instructions: ',0
  176. time_msg:        dc.b ' milliseconds',$D,$A,0
  177. lea_memory_msg:  dc.b $D,$A,'   LEA requisite memory:    ',0
  178. adda_memory_msg: dc.b       '   ADDA.L requisite memory: ',0
  179. memory_msg:      dc.b ' bytes',$D,$A,0
  180.  bss
  181.  align                          ; Align storage on a word boundary.
  182.                  ds.l     96
  183. stack:           ds.l      0
  184. program_end:     ds.l      0    ; Marks the end of program memory.
  185.  end
  186.  
  187.